JavaScript or other traditionally interpreted code, or other source code, may be compiled into byte code or machine code for example to enable the compiled code to be executed in place of the original traditionally interpreted code, which typically affords performance advantages. FIGS. 1A and 1B are block diagrams illustrating prior art systems for compiling source code, including source code in a traditionally interpreted programming language, such as JavaScript. In the example shown in FIG. 1A, source code 102 is compiled by a compiler 104 to generate machine code 106. In the example shown in FIG. 1B, source code 122 is processed by an initial code generator 124 to generate an initial intermediate representation of the source code. Subsequently, a compiler 126 is used to perform optimization processing on the intermediate representation and to generate machine code 128 based on the optimized intermediate representation.
There is a traditional approach used when compiling source code written in a traditionally interpreted or other language to generate machine code for execution in a garbage collected environment. This approach is to statically analyze the program structure of the source code to identify source code execution points where the requirements of garbage collection are satisfied. These requirements include the source code not allocating new objects and/or modifying existing objects. These requirements allow the garbage collector to safely update pointers in the case of a consolidating or “moving” garbage collector, and the execution points where these garbage collection operations can be done correctly may be referred to as “safepoints”. The static analysis of the program structure results in safepoint code being inserted at these execution points in connection with initial code generation, i.e., the first stage of code generation based directly on the original source code, such as the initial byte code generated by byte code generator 124 in the example shown in FIG. 1B. Optimizations traditionally have been performed on such initially generated intermediate representation prior to final, optimized machine code being generated. FIG. 2 is a flow diagram illustrating a prior art process for compiling source code. In the example shown in FIG. 2, source code (202) is analyzed to identify points in the source code in which safepoint code can be inserted (204), e.g., in connection with initial code generation based on the source code. Subsequent to initial code generation, optimizations are performed and optimized machine code generated (206).